﻿
@model IEnumerable<Cadcam7Moddel.Model.Loaitin>

@{
    ViewBag.Title = "Index";
}


<!-- Subheader -->
<a class="btn btn-subhead" data-toggle="collapse" data-target=".subhead-collapse">Toolbar<i class="icon-wrench"></i></a>
<div class="subhead-collapse collapse">
    <div class="subhead">
        <div class="container-fluid">
            <div id="container-collapse" class="container-collapse"></div>
            <div class="row-fluid">
                <div class="span12">
                    <div class="btn-toolbar" id="toolbar">
                        <div class="btn-wrapper" id="toolbar-new">
                            <a href="@Url.Action("Create")" class="btn btn-small btn-success">
                                <span class="icon-new icon-white"></span>
                                Thêm mới
                            </a>
                        </div>
                        <div class="btn-wrapper" id="toolbar-edit">
                            <button class="btn btn-small" id="Edit">
                                <span class="icon-edit"></span>
                                Sửa
                            </button>
                        </div>
                        <div class="btn-group divider"></div>
                        <div class="btn-wrapper" id="toolbar-delete">
                            <button class="btn btn-small">
                                <span class="icon-delete"></span>
                                Xóa
                            </button>
                        </div>
                        <div class="btn-wrapper" id="toolbar-clearfilter">
                            <button class="btn btn-small">
                                <span class="icon-unpublish"></span>
                                Bỏ lọc dữ liệu
                            </button>
                        </div>
                        <div class="btn-wrapper" id="toolbar-refresh">
                            <button class="btn btn-small">
                                <span class="icon-refresh"></span>
                                Làm mới
                            </button>
                        </div>
                        <div class="btn-group divider"></div>
                        <div class="btn-wrapper" id="toolbar-help">
                            <button rel="help" class="btn btn-small">
                                <span class="icon-question-sign"></span>
                                Help
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div style="margin-bottom: 20px"></div>
<!-- container-fluid -->
<div class="container-fluid container-main">
    <section id="content">
        <!-- Begin Content -->
        <div class="row-fluid">
            <div class="span12">

                <div id="system-message-container">
                </div>
                <div id="j-sidebar-container" class="span2">
                    <div id="sidebar">
						<div class="sidebar-nav">
				<ul id="submenu" class="nav nav-list">
							<li class="active">
								<a href="index.php?option=com_users&amp;view=users">Users</a>
							</li>
							<li>
								<a href="index.php?option=com_users&amp;view=groups">User Groups</a>
							</li>
							<li>
								<a href="index.php?option=com_users&amp;view=levels">Viewing Access Levels</a>
							</li>
							<li>
								<a href="index.php?option=com_users&amp;view=notes">User Notes</a>
							</li>
							<li>
								<a href="index.php?option=com_categories&amp;extension=com_users">Note Categories</a>
							</li>
					</ul>
							</div>
                    </div>
                </div>

                <!---->
                <div id="j-main-container" class="span10">

                    <!-- showcontent-->
                    <script type="text/javascript">
                        $(document).ready(function () {
                          		var theme = "arctic";
                            var url = "@Url.Action("jsonList")"; 
                            var rowID = 0;
							
						var getAdapter = function () {
                            var source = {
                                datatype: "json",
                                datafields: [
                                     { name: 'ID' },		  							     { name: 'Ten' },
 							     { name: 'Hienphai' }
											
								
                                ],
                                id: 'ID',
                                url: url
                            };


							   var dataAdapter = new $.jqx.dataAdapter(source);
							    return dataAdapter;
							   }
							  var imagerenderer = function (row, datafield, value) {
            return '<img style="margin:10px;10px;10px;10px;height:50px;" height="50" width="100" src="@Request.Url.GetLeftPart(UriPartial.Authority)/' + value + '"/>';
        }
        var imagerenderer_company = function (row, datafield, value) {
            return '<img style="margin:10px;10px;10px;10px;height:50px;" height="50" width="150" src="@Request.Url.GetLeftPart(UriPartial.Authority)/' + value + '"/>';
        }
        var flagimage = function (row, datafield, value) {
            return '<img style="margin-left: 38px;margin-top: 23px;width: auto;" height="25" width="40" src="@Request.Url.GetLeftPart(UriPartial.Authority)/' + value + '"/>';
        }					   
		var getLocalization = getlocalizationobj();
                            $("#grid_object").jqxGrid({
                                width: '100%',
            source: getAdapter(),
            rowsheight: 30,
            theme: theme,
            autoheight: true,
            pageable: true,
            pagermode: 'simple',
            sortable: true,
            pagesize: 10,
            showfilterrow: true,
            enabletooltips: true,
            autoshowfiltericon: true,
            selectionmode: 'checkbox',
            filterable: true,
            localization: getLocalization,
            showtoolbar: false,
            altrows: true,
            columns: [
                 { text: 'ID', datafield: 'ID', width:120 },
							  															{ text: '@Html.DisplayNameFor(m=>m.Ten)', datafield: 'Ten', width:120 },
							 															{ text: '@Html.DisplayNameFor(m=>m.Hienphai)', datafield: 'Hienphai', width:120 }
							                          

                                ]
             });


							$("#Edit").click(function () {
            var selectedrowindex = $("#grid_object").jqxGrid('getselectedrowindex');
            var rowscount = $("#grid_object").jqxGrid('getdatainformation').rowscount;
            var id = $("#grid_object").jqxGrid('getrowid', selectedrowindex);
            var dataRecord = $("#grid_object").jqxGrid('getrowdata', selectedrowindex);
            if (selectedrowindex >= 0) {
                location = "@Url.Action("Edit")/" + dataRecord.ID;
            }
            else {
                alert("Chọn dữ liệu cần sửa.");
            }
        });
        $("#toolbar-clearfilter").click(function () {
            $("#grid_object").jqxGrid('clearfilters');
        });
        $("#toolbar-refresh").click(function () {
            $("#grid_object").jqxGrid({
                source: getAdapter()
            });
            $("#grid_object").jqxGrid('clearselection');
        });
        $("#toolbar-delete").click(function () {
            var selectedrowindexes = $("#grid_object").jqxGrid('getselectedrowindexes');
            var rowscount = $("#grid_object").jqxGrid('getdatainformation').rowscount;
            if (selectedrowindexes.length != 0) {
                var comfim = confirm("Bạn có thật sự muốn xóa?");
                if (comfim) {
                    $("#grid_object").jqxGrid('beginupdate');
                    var resultid = 0;

                    for (var m = 0; m < selectedrowindexes.length; m++) {
                        var selectedrowindex = selectedrowindexes[selectedrowindexes.length - m - 1];
                        if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
                            var id = $("#grid_object").jqxGrid('getrowid', selectedrowindex);
                            var dataRecord = $("#grid_object").jqxGrid('getrowdata', selectedrowindex);
                            $("#grid_object").jqxGrid('deleterow', id);
                            $.ajax({
                                type: "POST",
                                url: "@Url.Action("ajDelete")",
                                datatype: "Json",
                                data: { id: dataRecord.ID },
                                success: function (result) {
                                   
                                }
                            });
                        }
                    }

                }
            }
            else {
                alert("Chọn dữ liệu cần xóa");
            }
            $("#grid_object").jqxGrid('endupdate');
            $("#grid_object").jqxGrid('clearselection');
            return false;
        });

                        });

                    </script>
                    <div id="grid_object" style="margin-left:4px;margin-top:10px;margin-bottom:10px;"></div>

                    <!-- end showcontent-->

                </div>
                <!---->
            </div>
        </div>
 </section>

</div>
